package com.study.ssm.factory.bean;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author zhoujunlin
 * @date 2023年07月23日 19:54
 * @desc
 */
@Getter
@Setter
public class ConnectionFactoryBean implements FactoryBean<Connection> {

    private String driverName;
    private String url;
    private String username;
    private String password;

    @Override
    public Connection getObject() throws Exception {
        Class.forName(this.driverName);
        return DriverManager.getConnection(url, username, password);
    }

    @Override
    public Class<?> getObjectType() {
        return Connection.class;
    }

    @Override
    public boolean isSingleton() {
        /**
         * 是否单例  连接对象不能是单例的  每次新建一个
         */
        return false;
    }
}
